package com.wenjie.terminal.util;

import android.content.Context;
import android.content.Intent;
import android.os.PowerManager;
import android.provider.Settings;

/**
 * 应用电池优化工具
 */
public class BatteryOptimizationUtil {

    /**
     * 将应用从电池优化名单中移除，防止后台进行被杀死
     */
    public static void checkAndOpenBatteryOptimizationSettings(Context context) {
        PowerManager powerManager = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
        if (powerManager != null && !powerManager.isIgnoringBatteryOptimizations(context.getPackageName())) {
            // 应用没有从电池优化名单中移除，打开电池优化设置界面
            Intent intent = new Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS);
            context.startActivity(intent);
        }
    }
}
